package com.winning.pmph.filter;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.winning.pmph.utils.PMPHAppUtil;
import lombok.extern.slf4j.Slf4j;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

@Slf4j
//@WebFilter(filterName = "logFilter", urlPatterns = {"/pmph/action/*"})
public class F2LogFilter implements Filter {
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        String crtId = IdWorker.getIdStr();
        log.debug("请求ID: " + crtId
                + ", 当前用户:  " + PMPHAppUtil.getCurrentUserEnName()
                + ", 访问接口:  " + request.getRequestURI()
                + ", 请求参数:  " + JSON.toJSONString(request.getParameterMap()));
        filterChain.doFilter(request , servletResponse);
        log.debug("请求ID: " + crtId + ", 结束");
    }
}